package com.bajiao.service.giveRule.impl;

import cn.hutool.core.util.ObjectUtil;
import com.bajiao.entity.giveRule.GiveRule;
import com.bajiao.mapper.giveRule.GiveRuleMapper;
import com.bajiao.service.giveRule.GiveRuleService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;

/**
 * @Description: 赠送规则
 * @Author: FanJq
 * @Date:   2024-12-12
 * @Version: V1.0
 */
@Service
public class GiveRuleServiceImpl extends ServiceImpl<GiveRuleMapper, GiveRule> implements GiveRuleService {

    /**
     * @Description
     * 根据code获取赠送规则
     * @date 2024/12/12 9:59
     * @author FanJq
     * @param code
     * @return {@link GiveRule}
    */
    @Override
    public GiveRule getByCode(String code) {
        return super.lambdaQuery().eq(GiveRule::getCode, code).one();
    }

    /**
     * @Description
     * 获取赠送金额
     * @date 2024/12/12 9:59
     * @author FanJq
     * @param code
     * @return {@link BigDecimal}
    */
    @Override
    public BigDecimal getGiveAmount(String code) {
        GiveRule giveRule = getByCode(code);
        return ObjectUtil.isNull(giveRule) || giveRule.getIsSwitch() == 0 ? BigDecimal.ZERO : giveRule.getGiveAmount();
    }
}
